<title>系统配置</title>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>系统管理</cite></a>
        <a><cite>系统配置</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief" lay-filter="TabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this" lay-id="website">网站配置</li>
                    <li lay-id="uploadConfig">上传配置</li>
                </ul>
                <div class="layui-tab-content" >
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form layui-form-pane" lay-filter="LAY-system-config-website">
                            <div class="layui-form-item">
                                <label class="layui-form-label">名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="webname" placeholder="请输入标题" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">标题</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" placeholder="请输入标题" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">关键词</label>
                                <div class="layui-input-block">
                                    <input type="text" name="keywords" placeholder="请输入关键词" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">描述</label>
                                <div class="layui-input-block">
                                    <input type="text" name="description" placeholder="请输入描述" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">版权</label>
                                <div class="layui-input-block">
                                    <textarea class="layui-textarea" name="copyright" rows="8"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="button" class="layui-btn" lay-submit="" lay-filter="LAY-system-config-formSubmit"><i class="layui-icon layui-icon-release"></i> 提 交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <blockquote class="layui-elem-quote layui-quote-nm" id="php_ini">
                            <p><i class="layui-icon layui-icon-about"></i> 当前 PHP 环境允许最大单个上传文件大小为: <span>--</span></p>
                            <p><i class="layui-icon layui-icon-about"></i> 当前 PHP 环境允许最大 POST 表单大小为: <span>--</span></p>
                        </blockquote>
                        <form class="layui-form layui-form-pane" lay-filter="LAY-system-config-uploadConfig">
                            <div class="layui-form-item" pane="">
                                <label class="layui-form-label">存储方式</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="storage" lay-filter="storage" value="local" title="本地" checked>
                                    <input type="radio" name="storage" lay-filter="storage" value="kodo" title="七牛云" >
                                    <input type="radio" name="storage" lay-filter="storage" value="cos" title="腾讯云" >
                                    <input type="radio" name="storage" lay-filter="storage" value="oss" title="阿里云" >
                                </div>
                            </div>
                            <fieldset class="layui-elem-field">
                                <legend>图片上传设置</legend>
                                <div class="layui-field-box">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">文件后缀</label>
                                        <div class="layui-input-block" style="width: 60%;">
                                            <div class="fairy-tag-container" style="min-height:auto;">
                                                <input type="text" id="image_type" class="fairy-tag-input" >
                                                <input type="hidden" name="image_type" >
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">文件大小</label>
                                        <div class="layui-input-inline" style="width: 180px;">
                                            <input type="number" name="image_size" lay-verify="number" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">KB 提示：1 M = 1024 KB</div>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset class="layui-elem-field">
                                <legend>附件上传设置</legend>
                                <div class="layui-field-box">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">文件后缀</label>
                                        <div class="layui-input-block" style="width: 60%;">
                                            <div class="fairy-tag-container" style="min-height:auto;">
                                                <input type="text" id="file_type" class="fairy-tag-input" >
                                                <input type="hidden" name="file_type" >
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">文件大小</label>
                                        <div class="layui-input-inline" style="width: 180px;">
                                            <input type="number" name="file_size" lay-verify="number" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">KB 提示：1 M = 1024 KB</div>
                                    </div>
                                </div>
                            </fieldset>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="button" class="layui-btn" lay-submit="" lay-filter="LAY-system-config-formSubmit"><i class="layui-icon layui-icon-release"></i> 提 交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['index', 'inputTag', 'baseMethods'], function () {
        let {$, form, layer, inputTag, baseMethods} = layui, siteKey = 'website';
        getData(siteKey);
        layui.element.on('tab(TabBrief)', function(elem) {
            siteKey = this.getAttribute('lay-id');
            if (siteKey === 'uploadConfig') {
                $("#image_type").prevAll().remove();
                $("#file_type").prevAll().remove();
            }
            getData(siteKey);
        });
        form.on('submit(LAY-system-config-formSubmit)', function(data) {
            layer.confirm('确认提交么？', function() {
                baseMethods.request({
                    url: "/system/config/"+siteKey+"/update",
                    type: 'put',
                    data: data.field,
                    done: function (result) {
                        result.code === 200 ? layer.msg(result.message, {icon: 6}) : layer.msg(result.message, {icon: 5});
                    }
                })
            });
        });
        function getData(siteKey) {
            baseMethods.request({
                url: "/system/config/data",
                data: {siteKey},
                done: function (result) {
                    if (result.code === 200) {
                        let data = result.data;
                        if (data && siteKey === 'uploadConfig') {
                            updateUploadConfig(data);
                        }
                        form.val('LAY-system-config-'+siteKey, data);
                    }
                }
            })
        }
        function updateUploadConfig(data) {
            let php_ini = $("#php_ini").find('p');
            php_ini.eq(0).find('span').text(data.upload_max_filesize);
            php_ini.eq(1).find('span').text(data.post_max_size);
            inputTag.render({
                elem: '#image_type',
                data: data.image_type,
                theme: ['fairy-bg-blue'],
                onChange: function (value) {
                    $('input[name=image_type]').val(value.join(','));
                }
            })
            inputTag.render({
                elem: '#file_type',
                data: data.file_type,
                theme: ['fairy-bg-blue'],
                onChange: function (value) {
                    $('input[name=file_type]').val(value.join(','));
                }
            });
        }
    });
</script>
